 $LOAD_PATH.unshift File.join(File.dirname(__FILE__),'../..','ext_pr1/lib')
 require 'ext_pr1_v4'

 class Array
   def to_int
     string = ""
     self.each {|x| string+= x.to_s}
     string.to_i
   end
   
   def even_only
     val = []
     self.each {|x| x % 2 == 0 ? val << x : nil }
     val
   end
   
   def flatten
     val = []
     self.each do |elem|
       if (elem.array?)
         tmp = elem.flatten
         if (tmp.array?)
           tmp.each { |x| val << x }
         end
       else
         val << elem
       end
     end
     
     val
   end
   
   def no_of_leaves
     val = 0
     self.each { |item| item.array? ? val += item.no_of_leaves : val += 1 }
     val
   end
   
 end
 
# puts([1, 2, 3, 4, 6, 7, 8].to_int)
 
 p([1, [2, 3, [4]], 5].flatten)
 
 p([1, [2, 3, [4]], 5].no_of_leaves)
 